package com.platform.modules.app.controller;

import com.platform.annotation.IgnoreAuth;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.bean.WxJsapiSignature;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/app/wxConfig")
public class AppWxConfigController {

    @Autowired
    private WxMpService wxService;

    @ApiOperation(value = "获取wxjs签名")
    @IgnoreAuth
    @GetMapping("/jsapiSignature")
    public WxJsapiSignature JsapiSignature(@RequestParam(name = "url", required = false) String url) throws WxErrorException {
        WxJsapiSignature wxJsapiSignature = wxService.createJsapiSignature(url);
        log.info(wxJsapiSignature.toString());
        return wxJsapiSignature;
    }
}
